<?php
$names = $_REQUEST["names"];
$emails = $_REQUEST["emails"];
$passwords = $_REQUEST["passwords"];
$question = $_REQUEST["question"];
$answer = $_REQUEST["answer"];
$action = $_REQUEST["action"];
echo "$names";
echo "$emails";
echo "$passwords";
echo "$question";
echo "$answer";
echo "$action";

include_once("conn.php");
//3.运行sql语句，执行增、删、改、查

//验证课程编号是否存在
/* $sql = "select * from admin where email='{$emails}'";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result)>0){
    //说明邮箱在数据库中已存在，已被注册过
    echo "<script>alert(错误，邮箱已重复)</script>";
}else{
    die("请正确输入参数");
} */
$sql="select * from admin where email='{$emails}'";
$msg = array(
  "code"=>"200",
  "cont"=>"可以注册",
  "data"=>1
 );
$result=mysqli_query($conn,$sql);
if (mysqli_num_rows($result)>0) {
 //说明该邮件在数据库中已存在，已被注册过
 $msg['code']="209";
 $msg['cont']="该邮箱已注册";
 $msg['data']=0;
 die(json_encode($msg));
}else{
 die(json_encode($msg));
}

/* if($action=="add"){
    $sql1 = "INSERT INTO `admin`(`nickname`, `email`, `password`, `question`, `answer`) VALUES ('{$names}','{$emails}','{$passwords}','{$question}','{$answer}')";
    $str = "数据插入成功";
}else{
    die("请正确输入参数");
}
$result1 = mysqli_query($conn,$sql1);

if($result1){
    echo "<script>alert('$str')</script>";
    header("Refresh:1;url=index.html");
}else{
    echo "<script>alert('数据插入失败')</script>";
} */
//4.关闭连接，释放资源
mysqli_close($conn);

?>